<?php
/**
 * 等比例缩放；
 * 指定一个宽高，求它缩放的倍数

    $path = "./images/";
    $pic = "5.jpg";
    $line = "x_";
    $maxw = 200;//指定宽高，进行等比例缩放；
    为了获取图片格式的值；１:gif,２:jpeg,３:png;
 */
header('Content-type:image/jpeg');

function fun($maxw,$maxh,$path,$pic){
    $str = getimagesize($path.$pic);
    switch($str[2]){
        case 1:
            $im = imagecreatefromgif($path.$pic);
            break;
        case 2:
            $im = imagecreatefromjpeg($path.$pic);
            break;
        case 3:
            $im = imagecreatefrompng($path.$pic);
            break;
    }
    $w = imagesx($im);
    $h = imagesy($im);
    if($w>$h){
        $max = $w/$maxw;
        $ww = $w/$max;
        $hh = $h/$max;
    }else{
        $max = $h/$maxh;
        $ww = $w/$max;
        $hh = $h/$max;
    }
    $img = imagecreatetruecolor($ww,$hh);
    imagecopyresampled($img,$im,0,0,0,0,$ww,$hh,$w,$h);
//    $y = date("Ymdhis");
    switch($str[2]){
        case 1:
            imagegif($img,"./pic/suolue/{$pic}");
            break;
        case 2:
            imagejpeg($img,"./pic/suolue/{$pic}");
            break;
        case 3:
            imagepng($img,"./pic/suolue/{$pic}");
            break;
    }
    imagedestroy($im);
    imagedestroy($img);
}

$maxw = 200;
$maxh = 200;
//$path = "../phpstorm/img/";
//$pic = "20.jpg";


//fun($maxw,$maxh,$path,$pic);
